﻿using System;
using AMM.Business;
using AMM.Model;
using AMM.Model.Store;

namespace AMM.UserControls {
    public partial class ProductOutStoreOrderSearchControl : BaseSearchControl {

        public override BaseSearchModel GetSearchModel() {
            int inStoreTypeValue = Convert.ToInt32(this.cmbInStoreType.SelectedValue);
            int orderStatusValue = Convert.ToInt32(this.cmbOrderStatus.SelectedValue);

            ProductOutStoreOrderSearchModel searchResult = new ProductOutStoreOrderSearchModel();
            searchResult.ProductOutStoreOrderCode = this.tbCode.Text;
            searchResult.ProductOutStoreDateStart = this.GetDateTimePickerValue(this.dtpCreateStart);
            searchResult.ProductOutStoreDateEnd = this.GetDateTimePickerValue(this.dtpCreateEnd);
            searchResult.ProductCode = this.tbProductCode.Text;
            searchResult.ProductOutStoreTypeId = inStoreTypeValue;
            searchResult.OrderStatus = orderStatusValue;

            if (inStoreTypeValue == 0) { searchResult.ProductOutStoreTypeId = null; }
            if (orderStatusValue == -1) { searchResult.OrderStatus = null; }

            return searchResult;
        }

        public override void ResetSearchModel() {
            this.tbCode.Clear();
            this.tbProductCode.Clear();
            this.dtpCreateStart.Checked = false;
            this.dtpCreateEnd.Checked = false;
            this.cmbInStoreType.SelectedIndex = 0;
            this.cmbOrderStatus.SelectedIndex = 0;
        }

        public ProductOutStoreOrderSearchControl() {
            this.InitializeComponent();
        }

        private void ProductOutStoreOrderSearchControl_Load(object sender, EventArgs e) {
            this.BindBasics(this.cmbInStoreType, BasicsType.ProductOutStoreType);
            this.BindAuditStatus(this.cmbOrderStatus);
        }
    }
}
